package action;

import entity.return_type.BooleanMsg;
import entity.return_type.DataNoPaging;
import util.file.FileDownload;
import util.file.FileUpload;
import util.HttpIOUtil;
import util.baidu.NetworkCaughtUtil;

public class FileAction extends SuperAction {

	private static final long serialVersionUID = 1L;

	public void fileUpload(){
        Object out = null;
		try {
			DataNoPaging dataNoPaging = new DataNoPaging();
			dataNoPaging.setData(FileUpload.fileUpload("", "", request));
			dataNoPaging.setMsg("上传成功");
			out = dataNoPaging;
		} catch (Exception e) {
			BooleanMsg msg = new BooleanMsg();
			msg.setSuccess(false);
			msg.setMsg("上传失败");
			e.printStackTrace();
		}
		HttpIOUtil.ObjectToWeb(response, out);
	}

	public void fileDownload() throws Exception{
		BooleanMsg out = new BooleanMsg();
		try {
			String filePath = params.getString("filePath");
			if(!FileDownload.fileDownload(filePath, response)) {
				out.setSuccess(false);
				HttpIOUtil.ObjectToWeb(response, out);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void musicDownload() throws Exception{
		BooleanMsg out = new BooleanMsg();
		try {
			String filePath = params.getString("filePath");
			if(!FileDownload.fileDownload(NetworkCaughtUtil.getProjectPath() + filePath, response)) {
				out.setSuccess(false);
				HttpIOUtil.ObjectToWeb(response, out);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
